package com.supermap.originTest;



import com.supermap.data.processing.CacheWriter;
import com.supermap.data.processing.cache.MultiProcessCacheBuilder;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;


public class MultiProcessCaching {

    /**
     * 程序入口点
     * The entrance of the programme.
     */
    public static void main(String[] args) {

		




		try {
			String sciFilePath = "E:\\MapData\\202410\\haitu\\cache\\map001\\map001\\map001.sci";

			Path source = Paths.get(sciFilePath);
			Path target = Paths.get("E:\\MapData\\202410\\haitu\\cache\\map001\\map001\\map001.sci");

			CacheWriter cacheWriter = new CacheWriter();


			//读取sci文件
			cacheWriter.FromConfigFile(sciFilePath);


			//这里修改比例尺等参数
			HashMap<Double, String> scales = cacheWriter.getCacheScaleCaptions();
			cacheWriter.getCacheBounds().setLeft(-174.1658947986);
			cacheWriter.getCacheBounds().setRight(-172);
			cacheWriter.getCacheBounds().setTop(62);
			cacheWriter.getCacheBounds().setBottom(59.96670103640001);
			//scales.put(1.0834093716513985E-7,"4");





			//留存sci备份
			int count = 1;
			Path newTarget = target;
			while (Files.exists(newTarget)) {
				String fileName = target.getFileName().toString();
				String newFileName = fileName.replaceFirst("\\.([^.]*)$", "_" + count + ".$1");
				newTarget = target.resolveSibling(newFileName);
				count++;
			}
			Files.copy(source, newTarget);
			System.out.println("文件移动成功，目标文件为: " + newTarget);


			//保存新的sci文件
			cacheWriter.ToConfigFile(sciFilePath);


			File sciFile = new File(sciFilePath);
			//生成缓存
			MultiProcessCacheBuilder.main(new String[]{cacheWriter.getWorkspacePath(),
					cacheWriter.getMapName(),
					sciFilePath,
					"E:\\MapData\\202410\\haitu\\cache\\map001"});
			//File doneSciFleName = new File(sciFile.getParent() + File.separator+"done"+File.separator+sciFile.getName());
			//文件还原
			//Files.move(doneSciFleName.toPath(), source);

		} catch (Exception e) {
			throw new RuntimeException(e);
		}finally {
			
		}








	}


}  

